Can't get a display albums function to work... php [closed]

Posted by Zhenia on Server Fault See other posts from Server Fault or by Zhenia
Published on 2012-09-11T21:08:19Z Indexed on 2012/09/11 21:40 UTC
Read the original article Hit count: 82

Filed under:

need your help with the code, please. I am trying to display an album from the database, but i just get some strange signs having no idea why... the signs are Albums

Help me out if you know how to solve this problem. how can i maKe the code to display name of the album and amount of images in it? i am sure all is fine with the db.

this is the function:

function get_albums() 
{
    $albums = array();
    // not always have got to put brackets

    $albums_query = "SELECT albums.album_id, albums.timestamp, albums.name, LEFT(albums.description, 50) as description, COUNT(images.image_id) as image_count
FROM albums 
LEFT JOIN images ON albums.album_id = images.album_id 
WHERE albums.user_id = '{$_SESSION['user_id']}' 
GROUP BY albums.album_id";
$res = mysql_query($albums_query) or die(mysql_error().'<br>'.$albums_query);

    while($albums_row = mysql_fetch_assoc($res)){
        $albums = array (

                'id' => $albums_row['album_id'],
                'timestamp'=> $albums_row['timestamp'],
                'name' => $albums_row['name'],
                'description' => $albums_row['description'],
                'count' =>$albums_row['image_count']



    );

    }

    return $albums;

}

and the other half of the code:

<?php

$albums = get_albums();

if(empty($albums)) {
    echo'<p>You don\'t have any albums</p>';
}else{
    foreach($albums as $album){
    echo'<p><a href="view_album.php?album_id=',$album['id'],'">',$album['name'],'</a>(',$album['count'],'images)<br /></p>';    
    }
    }

?>

© Server Fault or respective owner

Related posts about php